package com.alinesno.cloud.portal.desktop.web.thymeleaf;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alinesno.cloud.base.boot.entity.ManagerResourceEntity;
import com.alinesno.cloud.base.boot.service.IManagerResourceService;
import com.alinesno.cloud.common.web.base.bean.PageService;
import com.alinesno.cloud.portal.desktop.web.bean.MenusBean;
import com.alinesno.cloud.portal.desktop.web.entity.LinkPathTypeEntity;
import com.alinesno.cloud.portal.desktop.web.service.ILinkPathTypeService;
import com.alinesno.cloud.portal.desktop.web.service.IMenusService;

/**
 * 页面服务(供页面调用)
 * @author WeiXiaoJin
 * @since 2020年1月12日 上午11:22:40
 */
@Component("portalPageHandle")
public class PortalThymeleafPageService extends PageService {

	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(PortalThymeleafPageService.class) ; 

	@Autowired
	private ILinkPathTypeService linkPathTypeService ; 
	
	@Autowired
	private IMenusService menusService ; 
	
	@Autowired
	private IManagerResourceService managerResourceService ; 
	
	/**
	 * 列举出代码类型
	 * @param typeName
	 * @return 
	 */
	public List<LinkPathTypeEntity> linkTypeList() {
		List<LinkPathTypeEntity> list = linkPathTypeService.findAll() ; 
		return list ; 
	}	

	public List<MenusBean> menus() {
		List<MenusBean> beans = menusService.findNavigation() ; 
		return beans ; 
	}
	
	public ManagerResourceEntity get(String id) {
		return managerResourceService.findEntityById(id) ; 
	}

	public String getResourceName(String id) {
		if(StringUtils.isBlank(id)) {
			return "" ; 
		}
		ManagerResourceEntity e = managerResourceService.findEntityById(id) ; 
		return e == null ? "" : e.getResourceName() ;
	}
}
